<?php
/**
 * 添加测试菜单
 */

// MySQL连接配置
$host = '113.44.136.17';
$port = '3306';
$database = 'qiandao';
$username = 'qiandao';
$password = 'NGbks3HWx5PhSxDX';

try {
    $pdo = new PDO("mysql:host={$host};port={$port};dbname={$database};charset=utf8mb4", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    echo "=== 添加测试菜单 ===\n\n";
    
    // 查找打卡积分的一级菜单ID
    $stmt = $pdo->query("SELECT id FROM system_menu WHERE title = '打卡积分' AND pid = 0");
    $parentMenu = $stmt->fetch(PDO::FETCH_ASSOC);
    
    if (!$parentMenu) {
        echo "❌ 未找到'打卡积分'一级菜单\n";
        exit(1);
    }
    
    $pid1 = $parentMenu['id'];
    echo "✓ 找到打卡积分菜单 (ID: {$pid1})\n";
    
    // 删除旧的测试菜单
    $stmt = $pdo->prepare("DELETE FROM system_menu WHERE title = '测试页面' AND node = 'checkin/test/index'");
    $stmt->execute();
    
    // 插入测试菜单
    $stmt = $pdo->prepare("INSERT INTO system_menu (pid, title, icon, node, url, params, target, sort, status, create_at) VALUES (?, '测试页面', 'layui-icon layui-icon-test', 'checkin/test/index', '', '', '_self', 999, 1, NOW())");
    $stmt->execute([$pid1]);
    echo "✓ 插入测试菜单\n";
    
    echo "\n✅ 测试菜单添加成功！\n";
    echo "\n请刷新浏览器，在'打卡积分'菜单下应该能看到'测试页面'。\n";
    echo "如果测试页面能正常显示，说明框架工作正常，问题可能在权限配置上。\n";
    
} catch (PDOException $e) {
    echo "❌ 数据库错误: " . $e->getMessage() . "\n";
}
?>
